package com.dbtimer.dbupdate_spring.Service.ServiceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dbtimer.dbupdate_spring.Dao.*;
import com.dbtimer.dbupdate_spring.Entity.*;
import com.dbtimer.dbupdate_spring.Service.dsupdateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("dsupdateService")
public class dsupdateServiceImpl implements dsupdateService {

    @Autowired
    dmBaseConfigDAO dmBaseConfigDAO;
    @Autowired
    mysqlBaseConfigDAO mysqlBaseConfigDAO;
    @Override
    public void updateBaseConfig(){
        List<BaseConfigEntity> info=this.dmBaseConfigDAO.selectList(null);
        QueryWrapper<BaseConfigEntity> querytable=new QueryWrapper<>();
        mysqlBaseConfigDAO.delete(querytable);//清除mysql表内容
        //插入达梦表内容
        for (BaseConfigEntity inf:info){
            mysqlBaseConfigDAO.insert(inf);
            System.out.println(inf);
    }
    }
    
    @Autowired
    dmLastDataDAO dmLastDataDAO;
    @Autowired
    mysqlLastDataDAO mysqlLastDataDAO;
    @Override
    public void updateLastData(){
        List<LastDataEntity> info=dmLastDataDAO.selectList(null);
        QueryWrapper<LastDataEntity> querytable=new QueryWrapper<>();
        mysqlLastDataDAO.delete(querytable);//清除mysql表内容
        //插入达梦表内容
        for (LastDataEntity inf:info){
            mysqlLastDataDAO.insert(inf);
            System.out.println(inf);
        }
    }

    @Autowired
    dmOriginalMsgGPRSDAO dmOriginalMsgGPRSDAO;
    @Autowired
    mysqlOriginalMsgGPRSDAO mysqlOriginalMsgGPRSDAO;
    @Override
    public void updateOriginalMsgGPRS(){
        List<OriginalMsgGPRSEntity> info=dmOriginalMsgGPRSDAO.selectList(null);
        QueryWrapper<OriginalMsgGPRSEntity> querytable=new QueryWrapper<>();
        mysqlOriginalMsgGPRSDAO.delete(querytable);//清除mysql表内容
        //插入达梦表内容
        for (OriginalMsgGPRSEntity inf:info){
            mysqlOriginalMsgGPRSDAO.insert(inf);
            System.out.println(inf);
        }

    }

    @Autowired
    dmRunConfigDAO dmRunConfigDAO;
    @Autowired
    mysqlRunConfigDAO mysqlRunConfigDAO;
    @Override
    public void updateRunConfig(){
        List<RunConfigEntity> info=dmRunConfigDAO.selectList(null);
        QueryWrapper<RunConfigEntity> querytable=new QueryWrapper<>();
        mysqlRunConfigDAO.delete(querytable);//清除mysql表内容
        //插入达梦表内容
        for (RunConfigEntity inf:info){
            mysqlRunConfigDAO.insert(inf);
            System.out.println(inf);
        }
    }

    @Autowired
    dmSendCmdDAO dmSendCmdDAO;
    @Autowired
    mysqlSendCmdDAO mysqlSendCmdDAO;
    @Override
    public void updateSendCmd(){
        List<SendCmdEntity> info=dmSendCmdDAO.selectList(null);
        QueryWrapper<SendCmdEntity> querytable=new QueryWrapper<>();
        mysqlSendCmdDAO.delete(querytable);//清除mysql表内容
        //插入达梦表内容
        for (SendCmdEntity inf:info){
            mysqlSendCmdDAO.insert(inf);
            System.out.println(inf);
        }
    }

    @Autowired
    dmST_STBPRP_BDAO dmST_STBPRP_BDAO;
    @Autowired
    mysqlST_STBPRP_BDAO mysqlST_STBPRP_BDAO;
    @Override
    public void updateST_STBPRP_B(){
        List<ST_STBPRP_BEntity> info=dmST_STBPRP_BDAO.selectList(null);
        QueryWrapper<ST_STBPRP_BEntity> querytable=new QueryWrapper<>();
        mysqlST_STBPRP_BDAO.delete(querytable);//清除mysql表内容
        //插入达梦表内容
        for (ST_STBPRP_BEntity inf:info){
            mysqlST_STBPRP_BDAO.insert(inf);
            System.out.println(inf);
        }
    }

    @Autowired
    dmOriginalDataDAO dmOriginalDataDAO;
    @Autowired
    mysqlOriginalDataDAO mysqlOriginalDataDAO;
    @Override
    public void updateOriginalData(){
        List<OriginalDataEntity> info=dmOriginalDataDAO.selectList(null);
        QueryWrapper<OriginalDataEntity> querytable=new QueryWrapper<>();
        mysqlOriginalDataDAO.delete(querytable);//清除mysql表内容
        //插入达梦表内容
        for (OriginalDataEntity inf:info){
            mysqlOriginalDataDAO.insert(inf);
            System.out.println(inf);
        }
    }




@Override
   public void run(){

   updateBaseConfig();
   updateLastData();
   updateOriginalMsgGPRS();
   updateRunConfig();
   updateSendCmd();
   updateST_STBPRP_B();
   updateOriginalData();
   System.out.println("更新一次成功");

}

}
